<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-goodsList-add">
			<div class="form-group">	
				<label class="col-sm-3 control-label">物品排序：</label>
				<div class="col-sm-8">
					<input id="goodsSort" name="goodsSort" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">物品编号：</label>
				<div class="col-sm-8">
					<input id="goodsNumber" name="goodsNumber" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">物品名称：</label>
				<div class="col-sm-8">
					<input id="goodsName" name="goodsName" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">类别：</label>
				<div class="col-sm-8">
					<select id="sortId" name="sortId" class="form-control select2-hidden-accessible" >
						<option th:each="goodsSort:${goodsSorts}" th:value="${goodsSort.sortId}" th:text="${goodsSort.sortName}" th:disabled="${goodsSort.status == '1'}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">单位：</label>
				<div class="col-sm-8">
					<select id="goodsUnit" name="goodsUnit" class="form-control m-b" th:with="type=${@dict.getType('unit_list')}">
	                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
	                </select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<div class="form-control-static col-sm-offset-9">
					<button type="submit" class="btn btn-primary">提交</button>
					<button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
				</div>
			</div>
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script th:src="@{/ajax/libs/select/select2.js}"></script>
    <script type="text/javascript">
		var prefix = ctx + "store/goodsList"
		$("#form-goodsList-add").validate({
			rules:{
				goodsNumber:{
					required:true,
        			minlength: 1,
        			maxlength: 20,
        			remote: {
                        url: ctx + "store/goodsList/checkNumberUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                        	name : function() {
                                return $.common.trim($("#goodsNumber").val());
                            }
                        },
                        dataFilter: function(data, type) {
                        	return $.validate.unique(data);
                        }
                    }
				},
				goodsName:{
        			required:true,
        			minlength: 1,
        			maxlength: 20,
        			remote: {
                        url: ctx + "store/goodsList/checkNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                        	name : function() {
                                return $.common.trim($("#goodsName").val());
                            }
                        },
                        dataFilter: function(data, type) {
                        	return $.validate.unique(data);
                        }
                    }
        		},
			},
			messages: {
				"goodsNumber": {
                    remote: "编号已经存在"
                },
                "goodsName": {
                    remote: "名称已经存在"
                }
            },
			submitHandler: function(form) {
				$.operate.save(prefix + "/add", $('#form-goodsList-add').serialize());
			}
		});
		
		// h新建进入此页聚焦于第一输入框
		document.getElementsByName("goodsSort")[0].focus()
	</script>
</body>
</html>
